package com.itstyle.mytest.queue.blockingQueueTest;

/**
 * @author xianguang
 * @date 2019-12-31 16:19
 */
public class TestMyBlockingQueue {
    public static void main(String[] args) {
        MyBlockingQueue<String> blockingQueue=new MyBlockingQueue();
        Runnable producer=()->{
            for (int i = 0; i <1000 ; i++) {
                try {
                    Thread.sleep(10000);
                    blockingQueue.put(Thread.currentThread().getName());
                    System.out.println("生产者"+Thread.currentThread().getName()+"-"+i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        Runnable consumer=()->{
            while (true) {
                try {
                    blockingQueue.take();
                    System.out.println("消费者"+Thread.currentThread().getName());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        new Thread(producer).start();
        new Thread(consumer).start();
        new Thread(consumer).start();
        new Thread(consumer).start();
        new Thread(consumer).start();
    }
}
